package com.yazi.mxz.gather.main.store;

import java.util.List;

import com.myframework.smhj.common.tool.DateUtil;
import com.yazi.mxz.gather.common.App;
import com.yazi.mxz.gather.entity.repository.Store;
import com.yazi.mxz.gather.repository.StoreRepository;
import com.yazi.mxz.gather.service.StoreService;

/**
 * 上传店铺
 * @author mo_yq5
 * @date 2015-8-17
 */
public class StoreUpload extends Thread {
	
	private StoreRepository storeRepository;
	private StoreService storeService;
	
	
	public StoreUpload() {
		storeRepository = App.context.getBean(StoreRepository.class);
		storeService = App.context.getBean(StoreService.class);
	}

	@Override
	public void run() {
		List<Store> list = storeRepository.findAll();
		com.yazi.mxz.gather.entity.beans.Store storeOrc;
		for (Store storeMgo : list) {
			if (storeMgo.getIsUpload()) {
				//continue;
			}
			storeOrc = new com.yazi.mxz.gather.entity.beans.Store();
			storeOrc.setAddress(storeMgo.getAddr());
			storeOrc.setAddTime(DateUtil.getTimeStamp());
			storeOrc.setCompanyId(1l);
			storeOrc.setContacts(null);
			storeOrc.setDeliveryScore(0f);
			storeOrc.setDescr(null);
			storeOrc.setGoodsScore(0f);
			storeOrc.setIsNewOrder(false);
			storeOrc.setIsOpen(true);
			storeOrc.setIsOpenLocal(true);
			storeOrc.setIsOpenOnline(true);
			storeOrc.setIsRecommand(true);
			storeOrc.setLat((Math.random()*(2332-2213) + 2213)/100);
			storeOrc.setLng((Math.random()*(10851-10745) + 10745)/100);
			storeOrc.setLogo(null);
			storeOrc.setMemRemain(0);
			storeOrc.setName(storeMgo.getName());
			storeOrc.setPhone(storeMgo.getTel().split(" ")[0]);
			storeOrc.setPromRemain(0);
			storeOrc.setPutupRemain(0);
			storeOrc.setRecommandSort(new Double(Math.random() * 999999).longValue());
			storeOrc.setRegionId(97l);
			storeOrc.setRegionPath("广西南宁");
			storeOrc.setServiceScore(0f);
			storeOrc.setUpdateTime(DateUtil.getTimeStamp());
			storeService.persist(storeOrc);
			
			storeMgo.setIsUpload(true);
			storeRepository.save(storeMgo);
			System.out.println("成功添加: " + storeMgo.getName());
		}
	}
	
}
